local skel = fk.CreateSkill {
  name = "emo__huanzhuang",
}

Fk:loadTranslationTable{
  ["emo__huanzhuang"] = "换装",
  [":emo__huanzhuang"] = "游戏开始时，你获得5种“换装”标记。每轮开始时，你可以移去1种标记执行对应效果：<br>"..
  "①清新：移动场上三张装备牌，以此法获得牌的角色复原武将牌，且本轮每次至多受到1点的伤害。<br>".. -- 防御
  "②甜美：回复所有体力，本轮你失去红色牌后，你可以与一名其他角色各摸一张牌。<br>".. --支援
  "③典雅：进行一个额外回合，本轮你使用装备牌时摸一张牌，使用锦囊牌时可增加一个目标。<br>".. -- 过牌
  "④帅气：获得牌堆顶前二十张牌中的【杀】，本轮你成为牌目标后可使用【杀】。<br>".. -- 输出
  "⑤性感：令每名角色依次视为对你以外的角色使用【决斗】，本轮任意角色进入濒死状态时你摸两张牌。", -- 控制

  ["HZqingxin"] = "清新",
  [":HZqingxin"] = "清新：移动场上三张装备牌，以此法获得牌的角色复原武将牌，且本轮每次至多受到1点的伤害。",
  ["HZtianmei"] = "甜美",
  [":HZtianmei"] = "甜美：回复所有体力，本轮你失去红色牌后，你可以与一名其他角色各摸一张牌。",
  ["HZdianya"] = "典雅",
  [":HZdianya"] = "典雅：进行一个额外回合，本轮你使用装备牌时摸一张牌，使用锦囊牌时可增加一个目标。",
  ["HZshuaiqi"] = "帅气",
  [":HZshuaiqi"] = "帅气：获得牌堆顶前二十张牌中的【杀】，本轮你成为牌目标后可使用【杀】。",
  ["HZxinggan"] = "性感",
  [":HZxinggan"] = "性感：令每名角色依次视为对你以外的角色使用【决斗】，本轮任意角色进入濒死状态时你摸两张牌。",

  ["@@HZqingxin-round"] = "清新",
  ["@@HZtianmei-round"] = "甜美",
  ["@@HZdianya-round"] = "典雅",
  ["@@HZshuaiqi-round"] = "帅气",
  ["@@HZxinggan-round"] = "性感",

  ["#emo__huanzhuang-choice"] = "换装:你可以移去1种标记执行对应效果",
  ["@[:]emo__huanzhuang"] = "换装",
  ["#HZqingxin-choose"] = "清新：选择两名角色，移动一张装备牌（第%arg此，共3次）",
  ["#HZtianmei-draw"] = "甜美：你可以与一名其他角色各摸一张牌",
  ["#HZshuaiqi-slash"] = "帅气：你可以使用【杀】",
  ["#HZdianya-choose"] = "典雅：你可以为%arg额外指定一个目标",

  -- 清新
  ["$emo__huanzhuang1"] = "每一片落花，都将去往不同的地方。",
  ["$emo__huanzhuang2"] = "闭上眼睛，忘记一切，才能听见那些最纯粹的声音。",
  -- 甜美
  ["$emo__huanzhuang3"] = "你是你鼓励，让我有勇气迈出第一步。",
  ["$emo__huanzhuang4"] = "有你陪在身边，我就有了继续走下去的勇气。",
  -- 典雅
  ["$emo__huanzhuang5"] = "一元复始，万象更新。",
  ["$emo__huanzhuang6"] = "烽烟四起，凤鸟一鸣可抵千军。",
  -- 帅气
  ["$emo__huanzhuang7"] = "你逃不掉的，乖乖向我臣服吧。",
  ["$emo__huanzhuang8"] = "我立于顶端，我享有一切。",
  -- 性感
  ["$emo__huanzhuang9"] = "高贵的身份，幸福的温情，真实的爱……都将是我的东西。",
  ["$emo__huanzhuang10"] = "所有的人，都会臣服在我的脚下……献出他们的爱！",
}

skel:addEffect(fk.GameStart, {
  anim_type = "special",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@[:]emo__huanzhuang", {"HZqingxin","HZtianmei","HZdianya","HZshuaiqi","HZxinggan"})
  end,
})

skel:addEffect(fk.RoundStart, {
  anim_type = "special",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and #player:getTableMark("@[:]emo__huanzhuang") > 0
  end,
  on_cost = function (self, event, target, player, data)
    local choices = player:getTableMark("@[:]emo__huanzhuang")
    table.insert(choices, "Cancel")
    local choice = player.room:askToChoice(player, { choices = choices, skill_name = skel.name, prompt = "#emo__huanzhuang-choice", detailed = true })
    if choice ~= "Cancel" then
      event:setCostData(self, choice)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self)
    room:removeTableMark(player, "@[:]emo__huanzhuang", choice)


    if choice == "HZqingxin" then -- 清新
      room:notifySkillInvoked(player, skel.name, "drawcard")
      player:broadcastSkillInvoke(skel.name, math.random(1,2))
      for i = 1, 3 do
        if player.dead then break end
        local tos = room:askToChooseToMoveCardInBoard(player, { skill_name = skel.name, flag = "e",
        prompt = "#HZqingxin-choose:::"..i })
        if #tos == 0 then break end
        local move = room:askToMoveCardInBoard(player, {target_one = tos[1], target_two = tos[2], flag = "e",
        skill_name = skel.name })
        if move and move.to and move.to:isAlive() then
          move.to:reset()
          room:setPlayerMark(move.to, "@@HZqingxin-round", 1)
        end
      end

    elseif choice == "HZtianmei" then -- 甜美
      room:notifySkillInvoked(player, skel.name, "support")
      player:broadcastSkillInvoke(skel.name, math.random(3, 4))
      room:delay(1000)
      room:setPlayerMark(player, "@@HZtianmei-round", 1)
      room:recover { num = player.maxHp - player.hp, skillName = skel.name, who = player, recoverBy = player }

    elseif choice == "HZdianya" then -- 典雅
      room:notifySkillInvoked(player, skel.name, "drawcard")
      player:broadcastSkillInvoke(skel.name, math.random(5,6))
      room:delay(1000)
      room:setPlayerMark(player, "@@HZdianya-round", 1)
      player:gainAnExtraTurn(true, skel.name)

    elseif choice == "HZshuaiqi" then -- 帅气
      room:notifySkillInvoked(player, skel.name, "offensive")
      player:broadcastSkillInvoke(skel.name, math.random(7,8))
      room:delay(1000)
      room:setPlayerMark(player, "@@HZshuaiqi-round", 1)
      local cards = table.filter(room:getNCards(20), function (id)
        return Fk:getCardById(id).trueName == "slash"
      end)
      if #cards > 0 then
        room:obtainCard(player, cards, true, fk.ReasonPrey, player, skel.name)
      end

    elseif choice == "HZxinggan" then -- 性感
      room:notifySkillInvoked(player, skel.name, "control")
      player:broadcastSkillInvoke(skel.name, math.random(9,10))
      room:setPlayerMark(player, "@@HZxinggan-round", 1)
      local others = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
      for _, to in ipairs(room:getAlivePlayers()) do
        if not to.dead then
          room:askToUseVirtualCard(to, { name = "duel", skill_name = skel.name, cancelable = false, extra_data = {exclusive_targets = others} })
        end
      end
    end
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@[:]emo__huanzhuang", 0)
end)

skel:addEffect(fk.DamageInflicted, {
  is_delay_effect = true,
  mute = true,
  priority = 0,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:getMark("@@HZqingxin-round") ~= 0 and data.damage > 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data:changeDamage(1 - data.damage)
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    if player:getMark("@@HZtianmei-round") ~= 0 and not player.dead then
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip)
            and Fk:getCardById(info.cardId).color == Card.Red then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local to = player.room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = player.room:getOtherPlayers(player), skill_name = skel.name, prompt = "#HZtianmei-draw",
    })[1]
    if to then
      player:drawCards(1, skel.name)
      if to:isAlive() then
        to:drawCards(1, skel.name)
      end
    end
  end,
})

skel:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:getMark("@@HZdianya-round") ~= 0 and data.card.type ~= Card.TypeBasic and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if data.card.type == Card.TypeEquip then
      player:drawCards(1, skel.name)
    else
      local targets = data:getExtraTargets({bypass_distances = true})
      if #targets == 0 then return end
      local to = room:askToChoosePlayers(player, {
        min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
        prompt = "#HZdianya-choose:::"..data.card:toLogString(),
      })[1]
      if to then
        data:addTarget(to)
      end
    end
  end,
})

skel:addEffect(fk.TargetConfirmed, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:getMark("@@HZshuaiqi-round") ~= 0 and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local use = player.room:askToUseCard(player, {
      pattern = "slash", skill_name = skel.name, prompt = "#HZshuaiqi-slash",
    })
    if use then
      use.extraUse = true
      player.room:useCard(use)
    end
  end,
})

--[[
skel:addEffect("targetmod", {
  residue_func = function (self, player, skill, scope, card)
    if player:getMark("@@HZshuaiqi-round") ~= 0 and card and card.trueName == "slash" then
      return 3
    end
  end,
})
--]]

skel:addEffect(fk.EnterDying, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:getMark("@@HZxinggan-round") ~= 0 and not player.dead
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:drawCards(2, skel.name)
  end,
})

return skel
